package com.example.demo.controller;

import com.example.demo.common.utills.CommonResult;
import com.example.demo.entity.Macro;
import com.example.demo.entity.MouthData;
import com.example.demo.mapper.MacroMapper;
import com.example.demo.service.MacroService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.crypto.Mac;
import java.util.List;

@RestController
@RequestMapping("/macro")
@CrossOrigin(allowCredentials = "true")
public class MacroController {

    @Resource
    MacroService macroService;
    @Resource
    MacroMapper macroMapper;

    @RequestMapping("/queryAll")
    public CommonResult queryAll(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
                                 @RequestParam(value = "pageSize",required = false,defaultValue = "10")int pageSize,
                                 @RequestParam(value = "name",required = false,defaultValue = "")String name,int id){
        System.out.println(name+"    "+id);
        return macroService.selectAllMacro(pageNum, pageSize, name,id);
    }

    @RequestMapping("/queryAllOfNon")
    public CommonResult queryAllOfNon(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
                                      @RequestParam(value = "pageSize",required = false,defaultValue = "10")int pageSize,
                                      @RequestParam(value = "name",required = false,defaultValue = "")String name){
        PageHelper.startPage(pageNum, pageSize);
        List<Macro> macros1 = macroMapper.queryOfNon(name);
        PageInfo<List<Macro>> pageInfo=new PageInfo(macros1);
        return new CommonResult(200,"查询成功",pageInfo);
    }

    @RequestMapping("/queryFist")
    public CommonResult selectFist(){
        return new CommonResult(200,"查询成功",macroMapper.selectFist());
    }
//
//    @PostMapping("/queryDto")
//    public CommonResult queryDto(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
//                                 @RequestParam(value = "pageSize",required = false,defaultValue = "10")int pageSize,
//                                 @RequestParam(value = "name",required = false,defaultValue = "")String name,int id){
//        return macroService.resultBFB(pageNum,pageSize,name,id);
//    }

    @RequestMapping("/queryMouthData")
    public CommonResult selectMouthData(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
                                        @RequestParam(value = "pageSize",required = false,defaultValue = "10")int pageSize,
            @RequestParam(value = "Fid",required = false,defaultValue = "0")int Fid,
                                        @RequestParam(value = "year",required = false,defaultValue = "0")int year){
        return macroService.selectMouthData(pageNum,pageSize,Fid,year);
    }

    @RequestMapping("/updateMouthData")
    public CommonResult updateMouthData(@RequestBody MouthData mouthData){
        return macroService.updateMouthData(mouthData);
    }

    @RequestMapping("/addMouthData")
    public CommonResult addMouthData(int Fid,int year,int uid){
        return macroService.addMouthData(Fid, year,uid);
    }

    @RequestMapping("/querySeData")
    public CommonResult selectSeData(){
        return new CommonResult(200,"查询成功",macroMapper.selectSeData());
    }

    @RequestMapping("/queryThirData")
    public CommonResult queryThirData(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
                                      @RequestParam(value = "pageSize",required = false,defaultValue = "10")int pageSize,
                                      @RequestParam(value = "name",required = false,defaultValue = "")String name,int pid){
        PageHelper.startPage(pageNum, pageSize);
        List<Macro> macros = macroMapper.queryThirData(pid,name);
        PageInfo<List<Macro>> pageInfo=new PageInfo(macros);
        return new CommonResult(200,"查询成功",pageInfo);
    }

}
